// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PySurfaceAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <visit-config.h>
#include <ColorAttribute.h>
#include <ColorAttribute.h>

// ****************************************************************************
// Module: PySurfaceAttributes
//
// Purpose:
//   Attributes for the surface plot
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a SurfaceAttributes.
//
struct SurfaceAttributesObject
{
    PyObject_HEAD
    SurfaceAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewSurfaceAttributes(int);
std::string
PySurfaceAttributes_ToString(const SurfaceAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetLegendFlag())
        snprintf(tmpStr, 1000, "%slegendFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%slegendFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetLightingFlag())
        snprintf(tmpStr, 1000, "%slightingFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%slightingFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetSurfaceFlag())
        snprintf(tmpStr, 1000, "%ssurfaceFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%ssurfaceFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetWireframeFlag())
        snprintf(tmpStr, 1000, "%swireframeFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%swireframeFlag = 0\n", prefix);
    str += tmpStr;
    const char *limitsMode_names = "OriginalData, CurrentPlot";
    switch (atts->GetLimitsMode())
    {
      case SurfaceAttributes::OriginalData:
          snprintf(tmpStr, 1000, "%slimitsMode = %sOriginalData  # %s\n", prefix, prefix, limitsMode_names);
          str += tmpStr;
          break;
      case SurfaceAttributes::CurrentPlot:
          snprintf(tmpStr, 1000, "%slimitsMode = %sCurrentPlot  # %s\n", prefix, prefix, limitsMode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetMinFlag())
        snprintf(tmpStr, 1000, "%sminFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sminFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetMaxFlag())
        snprintf(tmpStr, 1000, "%smaxFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%smaxFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetColorByZFlag())
        snprintf(tmpStr, 1000, "%scolorByZFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%scolorByZFlag = 0\n", prefix);
    str += tmpStr;
    const char *scaling_names = "Linear, Log, Skew";
    switch (atts->GetScaling())
    {
      case SurfaceAttributes::Linear:
          snprintf(tmpStr, 1000, "%sscaling = %sLinear  # %s\n", prefix, prefix, scaling_names);
          str += tmpStr;
          break;
      case SurfaceAttributes::Log:
          snprintf(tmpStr, 1000, "%sscaling = %sLog  # %s\n", prefix, prefix, scaling_names);
          str += tmpStr;
          break;
      case SurfaceAttributes::Skew:
          snprintf(tmpStr, 1000, "%sscaling = %sSkew  # %s\n", prefix, prefix, scaling_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%slineWidth = %d\n", prefix, atts->GetLineWidth());
    str += tmpStr;
    const unsigned char *surfaceColor = atts->GetSurfaceColor().GetColor();
    snprintf(tmpStr, 1000, "%ssurfaceColor = (%d, %d, %d, %d)\n", prefix, int(surfaceColor[0]), int(surfaceColor[1]), int(surfaceColor[2]), int(surfaceColor[3]));
    str += tmpStr;
    const unsigned char *wireframeColor = atts->GetWireframeColor().GetColor();
    snprintf(tmpStr, 1000, "%swireframeColor = (%d, %d, %d, %d)\n", prefix, int(wireframeColor[0]), int(wireframeColor[1]), int(wireframeColor[2]), int(wireframeColor[3]));
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sskewFactor = %g\n", prefix, atts->GetSkewFactor());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smin = %g\n", prefix, atts->GetMin());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smax = %g\n", prefix, atts->GetMax());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scolorTableName = \"%s\"\n", prefix, atts->GetColorTableName().c_str());
    str += tmpStr;
    if(atts->GetInvertColorTable())
        snprintf(tmpStr, 1000, "%sinvertColorTable = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sinvertColorTable = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
SurfaceAttributes_Notify(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_SetLegendFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the legendFlag in the object.
    obj->data->SetLegendFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetLegendFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLegendFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetLightingFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the lightingFlag in the object.
    obj->data->SetLightingFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetLightingFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLightingFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetSurfaceFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the surfaceFlag in the object.
    obj->data->SetSurfaceFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetSurfaceFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetSurfaceFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetWireframeFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the wireframeFlag in the object.
    obj->data->SetWireframeFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetWireframeFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetWireframeFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetLimitsMode(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid limitsMode value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " OriginalData";
        ss << ", CurrentPlot";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the limitsMode in the object.
    obj->data->SetLimitsMode(SurfaceAttributes::LimitsMode(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetLimitsMode(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLimitsMode()));
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetMinFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the minFlag in the object.
    obj->data->SetMinFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetMinFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetMinFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetMaxFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the maxFlag in the object.
    obj->data->SetMaxFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetMaxFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetMaxFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetColorByZFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the colorByZFlag in the object.
    obj->data->SetColorByZFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetColorByZFlag(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetColorByZFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetScaling(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid scaling value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Linear";
        ss << ", Log";
        ss << ", Skew";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the scaling in the object.
    obj->data->SetScaling(SurfaceAttributes::Scaling(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetScaling(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetScaling()));
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetLineWidth(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the lineWidth in the object.
    obj->data->SetLineWidth(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetLineWidth(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLineWidth()));
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetSurfaceColor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the surfaceColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetSurfaceColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetSurfaceColor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the surfaceColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *surfaceColor = obj->data->GetSurfaceColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(surfaceColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(surfaceColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(surfaceColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(surfaceColor[3])));
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetWireframeColor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the wireframeColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetWireframeColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetWireframeColor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the wireframeColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *wireframeColor = obj->data->GetWireframeColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(wireframeColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(wireframeColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(wireframeColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(wireframeColor[3])));
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetSkewFactor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the skewFactor in the object.
    obj->data->SetSkewFactor(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetSkewFactor(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetSkewFactor());
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetMin(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the min in the object.
    obj->data->SetMin(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetMin(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMin());
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetMax(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the max in the object.
    obj->data->SetMax(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetMax(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMax());
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetColorTableName(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the colorTableName in the object.
    obj->data->SetColorTableName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetColorTableName(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetColorTableName().c_str());
    return retval;
}

/*static*/ PyObject *
SurfaceAttributes_SetInvertColorTable(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the invertColorTable in the object.
    obj->data->SetInvertColorTable(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SurfaceAttributes_GetInvertColorTable(PyObject *self, PyObject *args)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetInvertColorTable()?1L:0L);
    return retval;
}



PyMethodDef PySurfaceAttributes_methods[SURFACEATTRIBUTES_NMETH] = {
    {"Notify", SurfaceAttributes_Notify, METH_VARARGS},
    {"SetLegendFlag", SurfaceAttributes_SetLegendFlag, METH_VARARGS},
    {"GetLegendFlag", SurfaceAttributes_GetLegendFlag, METH_VARARGS},
    {"SetLightingFlag", SurfaceAttributes_SetLightingFlag, METH_VARARGS},
    {"GetLightingFlag", SurfaceAttributes_GetLightingFlag, METH_VARARGS},
    {"SetSurfaceFlag", SurfaceAttributes_SetSurfaceFlag, METH_VARARGS},
    {"GetSurfaceFlag", SurfaceAttributes_GetSurfaceFlag, METH_VARARGS},
    {"SetWireframeFlag", SurfaceAttributes_SetWireframeFlag, METH_VARARGS},
    {"GetWireframeFlag", SurfaceAttributes_GetWireframeFlag, METH_VARARGS},
    {"SetLimitsMode", SurfaceAttributes_SetLimitsMode, METH_VARARGS},
    {"GetLimitsMode", SurfaceAttributes_GetLimitsMode, METH_VARARGS},
    {"SetMinFlag", SurfaceAttributes_SetMinFlag, METH_VARARGS},
    {"GetMinFlag", SurfaceAttributes_GetMinFlag, METH_VARARGS},
    {"SetMaxFlag", SurfaceAttributes_SetMaxFlag, METH_VARARGS},
    {"GetMaxFlag", SurfaceAttributes_GetMaxFlag, METH_VARARGS},
    {"SetColorByZFlag", SurfaceAttributes_SetColorByZFlag, METH_VARARGS},
    {"GetColorByZFlag", SurfaceAttributes_GetColorByZFlag, METH_VARARGS},
    {"SetScaling", SurfaceAttributes_SetScaling, METH_VARARGS},
    {"GetScaling", SurfaceAttributes_GetScaling, METH_VARARGS},
    {"SetLineWidth", SurfaceAttributes_SetLineWidth, METH_VARARGS},
    {"GetLineWidth", SurfaceAttributes_GetLineWidth, METH_VARARGS},
    {"SetSurfaceColor", SurfaceAttributes_SetSurfaceColor, METH_VARARGS},
    {"GetSurfaceColor", SurfaceAttributes_GetSurfaceColor, METH_VARARGS},
    {"SetWireframeColor", SurfaceAttributes_SetWireframeColor, METH_VARARGS},
    {"GetWireframeColor", SurfaceAttributes_GetWireframeColor, METH_VARARGS},
    {"SetSkewFactor", SurfaceAttributes_SetSkewFactor, METH_VARARGS},
    {"GetSkewFactor", SurfaceAttributes_GetSkewFactor, METH_VARARGS},
    {"SetMin", SurfaceAttributes_SetMin, METH_VARARGS},
    {"GetMin", SurfaceAttributes_GetMin, METH_VARARGS},
    {"SetMax", SurfaceAttributes_SetMax, METH_VARARGS},
    {"GetMax", SurfaceAttributes_GetMax, METH_VARARGS},
    {"SetColorTableName", SurfaceAttributes_SetColorTableName, METH_VARARGS},
    {"GetColorTableName", SurfaceAttributes_GetColorTableName, METH_VARARGS},
    {"SetInvertColorTable", SurfaceAttributes_SetInvertColorTable, METH_VARARGS},
    {"GetInvertColorTable", SurfaceAttributes_GetInvertColorTable, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
SurfaceAttributes_dealloc(PyObject *v)
{
   SurfaceAttributesObject *obj = (SurfaceAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *SurfaceAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PySurfaceAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "legendFlag") == 0)
        return SurfaceAttributes_GetLegendFlag(self, NULL);
    if(strcmp(name, "lightingFlag") == 0)
        return SurfaceAttributes_GetLightingFlag(self, NULL);
    if(strcmp(name, "surfaceFlag") == 0)
        return SurfaceAttributes_GetSurfaceFlag(self, NULL);
    if(strcmp(name, "wireframeFlag") == 0)
        return SurfaceAttributes_GetWireframeFlag(self, NULL);
    if(strcmp(name, "limitsMode") == 0)
        return SurfaceAttributes_GetLimitsMode(self, NULL);
    if(strcmp(name, "OriginalData") == 0)
        return PyInt_FromLong(long(SurfaceAttributes::OriginalData));
    if(strcmp(name, "CurrentPlot") == 0)
        return PyInt_FromLong(long(SurfaceAttributes::CurrentPlot));

    if(strcmp(name, "minFlag") == 0)
        return SurfaceAttributes_GetMinFlag(self, NULL);
    if(strcmp(name, "maxFlag") == 0)
        return SurfaceAttributes_GetMaxFlag(self, NULL);
    if(strcmp(name, "colorByZFlag") == 0)
        return SurfaceAttributes_GetColorByZFlag(self, NULL);
    if(strcmp(name, "scaling") == 0)
        return SurfaceAttributes_GetScaling(self, NULL);
    if(strcmp(name, "Linear") == 0)
        return PyInt_FromLong(long(SurfaceAttributes::Linear));
    if(strcmp(name, "Log") == 0)
        return PyInt_FromLong(long(SurfaceAttributes::Log));
    if(strcmp(name, "Skew") == 0)
        return PyInt_FromLong(long(SurfaceAttributes::Skew));

    if(strcmp(name, "lineWidth") == 0)
        return SurfaceAttributes_GetLineWidth(self, NULL);
    if(strcmp(name, "surfaceColor") == 0)
        return SurfaceAttributes_GetSurfaceColor(self, NULL);
    if(strcmp(name, "wireframeColor") == 0)
        return SurfaceAttributes_GetWireframeColor(self, NULL);
    if(strcmp(name, "skewFactor") == 0)
        return SurfaceAttributes_GetSkewFactor(self, NULL);
    if(strcmp(name, "min") == 0)
        return SurfaceAttributes_GetMin(self, NULL);
    if(strcmp(name, "max") == 0)
        return SurfaceAttributes_GetMax(self, NULL);
    if(strcmp(name, "colorTableName") == 0)
        return SurfaceAttributes_GetColorTableName(self, NULL);
    if(strcmp(name, "invertColorTable") == 0)
        return SurfaceAttributes_GetInvertColorTable(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PySurfaceAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PySurfaceAttributes_methods[i].ml_name),
                PyString_FromString(PySurfaceAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PySurfaceAttributes_methods, self, name);
}

int
PySurfaceAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "legendFlag") == 0)
        obj = SurfaceAttributes_SetLegendFlag(self, args);
    else if(strcmp(name, "lightingFlag") == 0)
        obj = SurfaceAttributes_SetLightingFlag(self, args);
    else if(strcmp(name, "surfaceFlag") == 0)
        obj = SurfaceAttributes_SetSurfaceFlag(self, args);
    else if(strcmp(name, "wireframeFlag") == 0)
        obj = SurfaceAttributes_SetWireframeFlag(self, args);
    else if(strcmp(name, "limitsMode") == 0)
        obj = SurfaceAttributes_SetLimitsMode(self, args);
    else if(strcmp(name, "minFlag") == 0)
        obj = SurfaceAttributes_SetMinFlag(self, args);
    else if(strcmp(name, "maxFlag") == 0)
        obj = SurfaceAttributes_SetMaxFlag(self, args);
    else if(strcmp(name, "colorByZFlag") == 0)
        obj = SurfaceAttributes_SetColorByZFlag(self, args);
    else if(strcmp(name, "scaling") == 0)
        obj = SurfaceAttributes_SetScaling(self, args);
    else if(strcmp(name, "lineWidth") == 0)
        obj = SurfaceAttributes_SetLineWidth(self, args);
    else if(strcmp(name, "surfaceColor") == 0)
        obj = SurfaceAttributes_SetSurfaceColor(self, args);
    else if(strcmp(name, "wireframeColor") == 0)
        obj = SurfaceAttributes_SetWireframeColor(self, args);
    else if(strcmp(name, "skewFactor") == 0)
        obj = SurfaceAttributes_SetSkewFactor(self, args);
    else if(strcmp(name, "min") == 0)
        obj = SurfaceAttributes_SetMin(self, args);
    else if(strcmp(name, "max") == 0)
        obj = SurfaceAttributes_SetMax(self, args);
    else if(strcmp(name, "colorTableName") == 0)
        obj = SurfaceAttributes_SetColorTableName(self, args);
    else if(strcmp(name, "invertColorTable") == 0)
        obj = SurfaceAttributes_SetInvertColorTable(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
SurfaceAttributes_print(PyObject *v, FILE *fp, int flags)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)v;
    fprintf(fp, "%s", PySurfaceAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
SurfaceAttributes_str(PyObject *v)
{
    SurfaceAttributesObject *obj = (SurfaceAttributesObject *)v;
    return PyString_FromString(PySurfaceAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *SurfaceAttributes_Purpose = "Attributes for the surface plot";
#else
static char *SurfaceAttributes_Purpose = "Attributes for the surface plot";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(SurfaceAttributesType,         \
                  "SurfaceAttributes",           \
                  SurfaceAttributesObject,       \
                  SurfaceAttributes_dealloc,     \
                  SurfaceAttributes_print,       \
                  PySurfaceAttributes_getattr,   \
                  PySurfaceAttributes_setattr,   \
                  SurfaceAttributes_str,         \
                  SurfaceAttributes_Purpose,     \
                  SurfaceAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
SurfaceAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &SurfaceAttributesType
         || Py_TYPE(other) != &SurfaceAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    SurfaceAttributes *a = ((SurfaceAttributesObject *)self)->data;
    SurfaceAttributes *b = ((SurfaceAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static SurfaceAttributes *defaultAtts = 0;
static SurfaceAttributes *currentAtts = 0;

static PyObject *
NewSurfaceAttributes(int useCurrent)
{
    SurfaceAttributesObject *newObject;
    newObject = PyObject_NEW(SurfaceAttributesObject, &SurfaceAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new SurfaceAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new SurfaceAttributes(*defaultAtts);
    else
        newObject->data = new SurfaceAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapSurfaceAttributes(const SurfaceAttributes *attr)
{
    SurfaceAttributesObject *newObject;
    newObject = PyObject_NEW(SurfaceAttributesObject, &SurfaceAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (SurfaceAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
SurfaceAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewSurfaceAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef SurfaceAttributesMethods[] = {
    {"SurfaceAttributes", SurfaceAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *SurfaceAttributesObserver = 0;

std::string
PySurfaceAttributes_GetLogString()
{
    std::string s("SurfaceAtts = SurfaceAttributes()\n");
    if(currentAtts != 0)
        s += PySurfaceAttributes_ToString(currentAtts, "SurfaceAtts.", true);
    return s;
}

static void
PySurfaceAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("SurfaceAtts = SurfaceAttributes()\n");
        s += PySurfaceAttributes_ToString(currentAtts, "SurfaceAtts.", true);
        cb(s);
    }
}

void
PySurfaceAttributes_StartUp(SurfaceAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PySurfaceAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(SurfaceAttributesObserver == 0)
    {
        SurfaceAttributesObserver = new ObserverToCallback(subj,
            PySurfaceAttributes_CallLogRoutine, (void *)data);
    }

}

void
PySurfaceAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete SurfaceAttributesObserver;
    SurfaceAttributesObserver = 0;
}

PyMethodDef *
PySurfaceAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return SurfaceAttributesMethods;
}

bool
PySurfaceAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &SurfaceAttributesType);
}

SurfaceAttributes *
PySurfaceAttributes_FromPyObject(PyObject *obj)
{
    SurfaceAttributesObject *obj2 = (SurfaceAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PySurfaceAttributes_New()
{
    return NewSurfaceAttributes(0);
}

PyObject *
PySurfaceAttributes_Wrap(const SurfaceAttributes *attr)
{
    return WrapSurfaceAttributes(attr);
}

void
PySurfaceAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    SurfaceAttributesObject *obj2 = (SurfaceAttributesObject *)obj;
    obj2->parent = parent;
}

void
PySurfaceAttributes_SetDefaults(const SurfaceAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new SurfaceAttributes(*atts);
}

